package com.iris.live.services.services;

import com.iris.live.services.data.models.GroupAreaModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class OrgServiceImpl implements OrgService {
    @Autowired
    private GroupAreaService groupAreaService;

    public OrgServiceImpl() {
    }

    @Override
    public List getOrganizationList(String parentCode) {
        List<GroupAreaModel> orgs = groupAreaService.getGroupAreaList(parentCode);

        List<Map<String, String>> result = new ArrayList<>();
        if(orgs != null){
            for(GroupAreaModel org : orgs){
                Map<String, String> item = new HashMap<>();

                item.put("code", org.getPermit());
                item.put("text", org.getDealerName());

                result.add(item);
            }
        }

        return result;
    }
}
